$nl = [Environment]::NewLine function global:rip-getContextName { $result = "" $prop = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\RadioIP if($prop) { $result = $prop.'Context Identifier' } $result } function global:rip-getRipInstanceDllPath { $result = rip-getRipInstanceDllForTest if($result -eq "") { $assemblyName = "RipInstanceManaged.dll" $result = $assemblyName $assemblyPath = "" $prop = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\RadioIP\Data if($prop) { $assemblyPath = $prop.Path + "\..\licenseserver" $ripInstanceAssembly = $assemblyPath + "\" + $assemblyName; if(test-path $ripInstanceAssembly) { $result = $ripInstanceAssembly } } } $result } function global:rip-getRipInstanceDllForTest { $result = "" $tmpPath = get-location $assemblyPath = $tmpPath.path + "\RipInstanceManaged.dll"; if(test-path $assemblyPath) { $result = $assemblyPath } $result } function global:rip-getInstanceConfigFileName { $ripFile = "ripInstancesSettings.xml"; $result = "" $prop = Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SOFTWARE\RadioIP\Data if($prop) { $result = $prop.Path + "\" + $ripFile } else { $result = $ripFile } $result } function global:rip-getRipInstanceListener { $ripInstanceAssembly = rip-getRipInstanceDllPath [System.Reflection.Assembly]::LoadFrom($ripInstanceAssembly) | Out-Null $config = New-Object RipInstanceManaged.Configuration $settingsFile = $config.GetConfigurationDataFileName() $contextName = $config.GetContextName() $configData = $config.Load($settingsFile) $rip = new-object RipInstanceManaged.RipInstances Foreach ($ip in $configData.Settings.InterfaceAddresses) { $rip.ListenOn($ip.address, $configData.Settings.MulticastGroup, $configData.Settings.MulticastPort) } $rip } function global:rip-getMasterName { [cmdletbinding()] param ( [Parameter(Mandatory=$false)] [Uint32] $waitTime = 3000, [Parameter(Mandatory=$false)] [string] $contextName = "", [Parameter(Mandatory=$false)] [string] $verbosedisplay = "false" ) $result = "unknown" $rip = rip-getRipInstanceListener if($contextName -eq "") { $contextName = rip-getContextName } if($verbosedisplay -eq "true") { write-host "Waiting " $waitTime "ms for instance messages before determining the master gateway." } start-sleep -m $waitTime $instance = $rip.FindFirstActiveInstance($contextName, "ripstorage") if($instance) { $result = $instance._instance.node_name } if($verbosedisplay -eq "true") { write-host " Master gateway is : [" $result "]" } $result } function global:rip-filterXmlInstance() { [cmdletbinding()] param ( [Parameter(Mandatory=$true)] [xml] $xml, [Parameter(Mandatory=$false)] [string] $valueToMatch = "", [Parameter(Mandatory=$false)] [string] $itemToMatch = "" ) if($valueToMatch -ne "*" -And $valueToMatch -ne "" ) { $node = $xml.SelectSingleNode("//instance") # filter out unwanted instances while ($node -ne $null) { if($node.$itemToMatch -ne $valueToMatch) { $res = $node.ParentNode.RemoveChild($node) $node = $xml.SelectSingleNode("//instance") } else { $node = $node.NextSibling } } } $xml } function global:rip-getInstances() { [cmdletbinding()] param ( [Parameter(Mandatory=$true)] [object] $rip, [Parameter(Mandatory=$false)] [string] $contextName = "", [Parameter(Mandatory=$false)] [string] $nodeName = "*", [Parameter(Mandatory=$false)] [string] $instancename = "*" ) # by default, our context name if($contextName -eq "") { $contextName = rip-getContextName } $xml = [xml]($rip.ReportXML()) $node = $xml.SelectSingleNode("//instance") $xml = rip-filterXmlInstance -xml $xml -itemToMatch contextName -valueToMatch $contextName $xml = rip-filterXmlInstance -xml $xml -itemToMatch nodeName -valueToMatch $nodeName $xml = rip-filterXmlInstance -xml $xml -itemToMatch instancename -valueToMatch $instancename $xml } <# .SYNOPSIS Displays the currently discovered instances. .PARAMETER loopDelayMilliSecs Delay between each loop, in milliseconds. default to 1000 milliseconds between each loop execution. .PARAMETER loops Number of loops to perform. Default to 0 which will loop infinitely. .PARAMETER contextName Context to watch for. Defaults to "" (empty string), which will display instances for the context of the machine (registry : HKLM\Software\Radioip\Context Identifier). If "*" is specified, instances form all discovered contexts will be displayed. .PARAMETER nodeName Filters out all results except for the provided node name. Ex: rip-showInstances -nodeName Server01 .PARAMETER instancename Filters out all results except for the provided instance name. Ex: rip-showInstances -instanceName TheRock .PARAMETER outputToFile Specify the optional output file to append the results to. .PARAMETER logDifferencesOnly Only log when the result changes. Prevents displaying results at every loop when nothing changes. .EXAMPLE rip-showInstances -contextName abc Shows instances of the abc context name. .EXAMPLE rip-showInstances -loopDelayMilliSecs 2000 -contextName abc Shows instances of the abc context name, pausing 2 seconds between each display loop. .EXAMPLE rip-showInstances -loopDelayMilliSecs 2000 -contextName * Shows instances of all discovered contexts, pausing 2 seconds between each display loop. .EXAMPLE rip-showInstances -contextName * -nodename Server01 Shows instances of all discovered contexts only for node named Server01. .EXAMPLE rip-showInstances -contextName * -outputToFile c:\test.log Shows instances of all discovered contexts and appends the results in the specified file. #> function global:rip-showInstances() { [cmdletbinding()] param ( [Parameter(Mandatory=$false)] [Uint32] $loopDelayMilliSecs = 1000, [Parameter(Mandatory=$false)] [Uint32] $loops = 0, #infinite [Parameter(Mandatory=$false)] [string] $contextName = "", [Parameter(Mandatory=$false)] [string] $nodeName = "*", [Parameter(Mandatory=$false)] [string] $instancename = "*", [Parameter(Mandatory=$false)] [string] $outputToFile = "", [Parameter(Mandatory=$false)] [bool] $logDifferencesOnly = $FALSE ) # by default, our context name if($contextName -eq "") { $contextName = rip-getContextName } $rip = rip-getRipInstanceListener $lastXml = "" $infiniteLooping = $FALSE if($loops -eq 0) { $infiniteLooping = $TRUE; } $outputMessage = "" $currentLoop = 0 while($infiniteLooping -Or $currentLoop -lt $loops) { $currentLoop = $currentLoop + 1 $date = get-date $outputMessage = $date.tostring() + $nl $outputMessage += "Context : " + $contextName + $nl $xml = rip-getInstances -rip $rip -contextName $contextName -nodeName $nodeName -instanceName $instanceName $newXml = $xml.outerxml $log = $TRUE if($logDifferencesOnly -eq $TRUE) { if($lastXml -eq "") { $lastXml = $newXml } else { if($lastXml -ne $newXml) { $lastXml = $newXml } else { $log = $FALSE } } } #write-output $log if($log -eq $TRUE) { if($xml.instances.ChildNodes.Count -gt 0) { $outputMessage += "Total number of instances : [" + $xml.instances.ChildNodes.count + "]" + $nl # count active nodes $activeCount = 0 $node = $xml.SelectSingleNode("//instance") while ($node -ne $null) { if($node.active -eq "True") { $activeCount = $activeCount + 1 } $node = $node.NextSibling } $outputMessage += "Total number of active instances : [" + $activeCount + "]" + $nl $outputMessage += $xml.instances.instance | sort-object -property nodename,instancename | Format-Table -Autosize | out-string #$outputMessage += $logDifferencesOnly # $outputMessage += $lastXml } else { $outputMessage += "No instances found." + $nl } write-output $outputMessage if($outputToFile -ne "") { $outputMessage | Add-Content -Path $outputToFile } } start-sleep -m $loopDelayMilliSecs } } function global:rip-showInstancesMinimal() { rip-showInstances -loopDelayMilliSecs 100 -logDifferencesOnly $true } Write-Host -ForegroundColor Red @" rip-Instances 3.11.2 loaded. (c) Radio IP Software 2014 "@ write-host -ForegroundColor White @" Available functions: rip-showInstances Shows the current instances discovered on the network rip-showInstancesMinimal Shows the current instances discovered on the network (-loopDelayMilliSecs 100 -logDifferencesOnly $true) rip-getMasterName Returns the name of the master server rip-getContextName Returns the name of the context of the current machine (registry) "@ #clear-host #rip-showInstances -logDifferencesOnly $TRUE -loopDelayMilliSecs 100